<?php

class Tags extends BaseTags
{
	public function __toString() {
		return $this->getName();
	}
	
	public static function insertTag($name) {
		$a = DbFinder::from('Tags')
				->where('Name',trim(mb_strtolower($name,'UTF-8')))
				->find();
		if(!empty($a)) {
			return $a[0]->getId();
		} else {
			$obj = new Tags();
			$obj->setName(trim(mb_strtolower($name,'UTF-8')));
			$obj->save();			
			return $obj->getId();
		}
	}
	
	public static function getListTagsByString($news_id)
	{
		$a = DbFinder::from('NewsTags')
				->where('NewsId',$news_id)
				->find();
		if(!empty($a)) {
			$tmp = '';
			$i = 0;
			foreach($a as $value) {
				$i++;
				$item = TagsPeer::retrieveByPK($value->getTagsId());
				$tmp .= $item->getName();
				if($i<count($a)) $tmp .= ',';
			}
			return $tmp;
		} else {
			return '';
		}
	}
}
